/**
 * 
 */
package com.cp16.tss.validation;

import java.awt.Color;

import com.cp16.tss.common.Constants;
import com.cp16.tss.form.ServiceAddForm;

/**
 * @author ADMIN
 *
 */
public class ServiceValidation {
	
	public static boolean validateServiceAddForm(ServiceAddForm serviceAddForm){
		boolean flag;
		boolean serviceIdFlag = validateServiceIdAddForm(serviceAddForm);
		boolean serviceNameFlag = validateServiceNameAddForm(serviceAddForm);
		boolean servicePriceFlag = validateServicePrice(serviceAddForm);
		flag = serviceIdFlag && serviceNameFlag && servicePriceFlag;
		return flag;
	}
	
	public static boolean validateServiceIdAddForm(ServiceAddForm serviceAddForm){
		String serviceId = serviceAddForm.getTxtServiceId().getText();
		boolean serviceIdFlag = false;
		if(serviceId.equals(Constants.BLANK)){
			serviceAddForm.getLblIdReq().setText("Service ID is required");
			serviceAddForm.getLblIdReq().setForeground(Color.RED);
			serviceIdFlag = false;
		} else {
			serviceAddForm.getLblIdReq().setText(Constants.BLANK);
			serviceIdFlag = true;
		}
		return serviceIdFlag;
	}
	
	public static boolean validateServiceNameAddForm(ServiceAddForm serviceAddForm){
		String serviceName = serviceAddForm.getTxtServiceName().getText();
		boolean serviceNameFlag = false;
		if(serviceName.equals(Constants.BLANK)){
			serviceAddForm.getLblServiceNameReq().setText("Service name is required");
			serviceAddForm.getLblServiceNameReq().setForeground(Color.RED);
			serviceNameFlag = false;
		} else if (!CommonValidation.isUsername(serviceName)){
			serviceAddForm.getLblServiceNameReq().setText("Service name is not right format");
			serviceAddForm.getLblServiceNameReq().setForeground(Color.RED);
			serviceNameFlag = false;
		} else {
			serviceAddForm.getLblServiceNameReq().setText(Constants.BLANK);
			serviceNameFlag = true;
		}
		return serviceNameFlag;
	}
	
	public static boolean validateServicePrice(ServiceAddForm serviceAddForm){
		String servicePrice = serviceAddForm.getTxtServicePrice().getText();
		boolean servicePriceFlag = false;
		if(servicePrice.equals(Constants.BLANK)){
			serviceAddForm.getLblPriceReq().setText("Service price is required");
			serviceAddForm.getLblPriceReq().setForeground(Color.RED);
			servicePriceFlag = false;
		} else if (!CommonValidation.isNummeric(servicePrice)){
			serviceAddForm.getLblPriceReq().setText("Service price is not right format");
			serviceAddForm.getLblPriceReq().setForeground(Color.RED);
			servicePriceFlag = false;
		} else {
			serviceAddForm.getLblPriceReq().setText(Constants.BLANK);
			servicePriceFlag = true;
		}
		return servicePriceFlag;
	}
	
	
}
